package dao;

import java.util.ArrayList;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import beans.Categorie;

public class CategorieDao {

	private EntityManagerFactory emf = Persistence
			.createEntityManagerFactory("connection");
	private EntityManager em = emf.createEntityManager();

	public CategorieDao() {

	}

	@SuppressWarnings("unchecked")
	public ArrayList<Categorie> getAllCategories() {
		return (ArrayList<Categorie>) em.createQuery(
				"SELECT categorie FROM Categorie categorie").getResultList();
	}

	public Categorie getCategorieById(int id) {
		return (Categorie) em.createQuery(
				"SELECt categorie FROM Categorie categorie WHERE categorie.id="
						+ id).getSingleResult();
	}
}
